[WEB-6816]chore: added support for pql filters#39
[WEB-6816]chore: added support for pql filters#39sangeethailango wants to merge 5 commits intomainfrom
Conversation
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
There was a problem hiding this comment.
Pull request overview
Adds SDK support for filtering work item listings via PQL by extending the list params type and introducing a unit test to validate the behavior.
Changes:
- Added optional
pqltoListWorkItemsParamsforworkItems.list(...)query filtering. - Added a unit test that exercises listing work items with a PQL filter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/models/WorkItem.ts |
Extends list params typing to include pql for PQL-based filtering. |
tests/unit/work-items/work-items.test.ts |
Adds a test case for pql filtering when listing work items. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const allWorkItems = await client.workItems.list(workspaceSlug, projectId); | ||
| const priority = allWorkItems.results[0]?.priority ?? "none"; | ||
|
|
||
| const filtered = await client.workItems.list(workspaceSlug, projectId, { | ||
| pql: `priority IN ("${priority}")`, | ||
| }); |
There was a problem hiding this comment.
This test can produce false positives: if the first listed work item has no priority (or a value not supported by PQL), the fallback to "none" can yield an empty filtered result set, and the assertions still pass because the loop doesn’t run. Consider making the test deterministic by setting a known priority on the created workItem (or selecting a work item with a defined priority) and building the PQL from that known value.
📝 WalkthroughWalkthroughAdds an optional Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/models/WorkItem.ts`:
- Around line 51-52: The file has Prettier formatting violations around the
expanded mapped type for WorkItem (the line referencing WorkItemExpandableFields
and the mapped type for Expanded/WorkItem); run your formatter (prettier) to
reformat src/models/WorkItem.ts and fix spacing/semicolons so the mapped type
line for [K in Expanded]: K extends keyof WorkItemExpandableFields ?
WorkItemExpandableFields[K] : never; matches project style, then commit the
formatted file.
In `@tests/unit/work-items/work-items.test.ts`:
- Around line 93-97: The test currently can pass vacuously when filtered.results
is empty; after verifying filtered and that filtered.results is an array, add an
assertion that filtered.results.length is greater than 0 to ensure at least one
item is returned, then continue the existing loop asserting each wi.priority
equals the expected priority (references: filtered, filtered.results, priority).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c665f4e4-0733-4ab0-9de4-41538a4a4f3b
📒 Files selected for processing (2)
src/models/WorkItem.tstests/unit/work-items/work-items.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/work-items/work-items.test.ts (1)
85-105: Ensure created test data is always cleaned up (Line 104).If any assertion fails before Line 104,
pqlWorkItemis not deleted. Wrap assertions intry/finallyso cleanup always runs.Proposed refactor
it("should list work items with pql filter", async () => { const name = randomizeName(); const pqlWorkItem = await client.workItems.create(workspaceSlug, projectId, { name, priority: "high", }); - const filtered = await client.workItems.list(workspaceSlug, projectId, { - pql: 'priority IN ("high")', - }); - - expect(filtered).toBeDefined(); - expect(Array.isArray(filtered.results)).toBe(true); - expect(filtered.results.length).toBeGreaterThan(0); - expect(filtered.results.find((wi) => wi.id === pqlWorkItem.id)).toBeDefined(); - for (const wi of filtered.results) { - expect(wi.priority).toBe("high"); - } - - await client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!); + try { + const filtered = await client.workItems.list(workspaceSlug, projectId, { + pql: 'priority IN ("high")', + }); + + expect(filtered).toBeDefined(); + expect(Array.isArray(filtered.results)).toBe(true); + expect(filtered.results.length).toBeGreaterThan(0); + expect(filtered.results.find((wi) => wi.id === pqlWorkItem.id)).toBeDefined(); + for (const wi of filtered.results) { + expect(wi.priority).toBe("high"); + } + } finally { + await client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!); + } });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/work-items/work-items.test.ts` around lines 85 - 105, The test "should list work items with pql filter" creates pqlWorkItem via client.workItems.create but deletes it only at the end, so if an assertion throws the created item may leak; wrap the assertions (the body between creation and deletion) in a try/finally and perform client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!) in the finally block, guarding the delete with a check that pqlWorkItem and pqlWorkItem.id are defined to avoid runtime errors; this ensures cleanup even if any expect calls fail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unit/work-items/work-items.test.ts`:
- Around line 85-105: The test "should list work items with pql filter" creates
pqlWorkItem via client.workItems.create but deletes it only at the end, so if an
assertion throws the created item may leak; wrap the assertions (the body
between creation and deletion) in a try/finally and perform
client.workItems.delete(workspaceSlug, projectId, pqlWorkItem.id!) in the
finally block, guarding the delete with a check that pqlWorkItem and
pqlWorkItem.id are defined to avoid runtime errors; this ensures cleanup even if
any expect calls fail.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6900ada8-f485-43a9-8052-4e6f7765fadd
📒 Files selected for processing (2)
src/models/WorkItem.tstests/unit/work-items/work-items.test.ts
✅ Files skipped from review due to trivial changes (1)
- src/models/WorkItem.ts
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/unit/work-items/work-items.test.ts`:
- Around line 95-103: The PQL test is non-deterministic because 'priority IN
("high")' can return many items across pages; change the call to
client.workItems.list (used with workspaceSlug, projectId) to either include a
PQL clause that uniquely identifies the created test item (e.g., add name or id:
`priority IN ("high") AND name = "..."` or use the test-created identifier
stored in pqlWorkItem) or set explicit pagination/sorting so the created item is
guaranteed to appear (e.g., request a sufficiently large page size and sort by
created/updated timestamp descending). Update the test assertions to use that
tightened PQL or pagination to reliably find pqlWorkItem in filtered.results.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: af10a7d3-30de-4928-9363-5a002b3489c5
📒 Files selected for processing (2)
package.jsontests/unit/work-items/work-items.test.ts
✅ Files skipped from review due to trivial changes (1)
- package.json
| const filtered = await client.workItems.list(workspaceSlug, projectId, { | ||
| pql: 'priority IN ("high")', | ||
| }); | ||
|
|
||
| expect(filtered).toBeDefined(); | ||
| expect(Array.isArray(filtered.results)).toBe(true); | ||
| expect(filtered.results.length).toBeGreaterThan(0); | ||
| expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined(); | ||
| for (const wi of filtered.results) { |
There was a problem hiding this comment.
Make the PQL assertion deterministic to avoid pagination-related flakiness.
The filter priority IN ("high") is broad, so on busy projects your created item may not be in the returned page even when PQL works, causing intermittent failures (Line 95–103). Narrow the query to the created entity (e.g., include name/identifier in PQL) or set explicit pagination/sorting to ensure the created item is in-scope.
💡 Suggested test hardening
- const filtered = await client.workItems.list(workspaceSlug, projectId, {
- pql: 'priority IN ("high")',
- });
+ const filtered = await client.workItems.list(workspaceSlug, projectId, {
+ // Keep the PQL test focused on the created fixture and avoid page-order flakiness.
+ pql: `priority IN ("high") AND name = "${name}"`,
+ });📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const filtered = await client.workItems.list(workspaceSlug, projectId, { | |
| pql: 'priority IN ("high")', | |
| }); | |
| expect(filtered).toBeDefined(); | |
| expect(Array.isArray(filtered.results)).toBe(true); | |
| expect(filtered.results.length).toBeGreaterThan(0); | |
| expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined(); | |
| for (const wi of filtered.results) { | |
| const filtered = await client.workItems.list(workspaceSlug, projectId, { | |
| // Keep the PQL test focused on the created fixture and avoid page-order flakiness. | |
| pql: `priority IN ("high") AND name = "${name}"`, | |
| }); | |
| expect(filtered).toBeDefined(); | |
| expect(Array.isArray(filtered.results)).toBe(true); | |
| expect(filtered.results.length).toBeGreaterThan(0); | |
| expect(filtered.results.find((wi) => wi.id === pqlWorkItem!.id)).toBeDefined(); | |
| for (const wi of filtered.results) { |
🧰 Tools
🪛 ESLint
[error] 99-99: 'expect' is not defined.
(no-undef)
[error] 100-100: 'expect' is not defined.
(no-undef)
[error] 101-101: 'expect' is not defined.
(no-undef)
[error] 102-102: 'expect' is not defined.
(no-undef)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/unit/work-items/work-items.test.ts` around lines 95 - 103, The PQL test
is non-deterministic because 'priority IN ("high")' can return many items across
pages; change the call to client.workItems.list (used with workspaceSlug,
projectId) to either include a PQL clause that uniquely identifies the created
test item (e.g., add name or id: `priority IN ("high") AND name = "..."` or use
the test-created identifier stored in pqlWorkItem) or set explicit
pagination/sorting so the created item is guaranteed to appear (e.g., request a
sufficiently large page size and sort by created/updated timestamp descending).
Update the test assertions to use that tightened PQL or pagination to reliably
find pqlWorkItem in filtered.results.
This pull request adds support for filtering work items using PQL (Project Query Language) in the work items API. The main changes introduce a new
pqlparameter to the work item listing functionality and include a corresponding unit test to ensure the filter works as expected.API Enhancements:
pqlparameter to theListWorkItemsParamsinterface insrc/models/WorkItem.ts, enabling clients to filter work items using PQL queries.Testing Improvements:
work-items.test.tsto verify that thepqlfilter returns only work items matching the specified criteria.Summary by CodeRabbit
New Features
Tests
Chores